// ReportQueryHandler.h: interface for the ReportQueryHandler class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_REPORTQUERYHANDLER_H__F100DF8B_E06B_49FE_A442_0905A589EE45__INCLUDED_)
#define AFX_REPORTQUERYHANDLER_H__F100DF8B_E06B_49FE_A442_0905A589EE45__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "BaseRequestHandler.h"

struct ReportAckStruct;
struct ReportTempletHeader;
class ReportField;
struct MonUnitItem;
struct ReportItem;
struct ReportItemEx;
class RealtimeRecordManager;
struct ReportTempletAckStruct;

class ReportQueryHandler : public BaseRequestHandler
{
public:
	bool IsDefFileExExist(CTime timeBegin);
	ReportQueryHandler(const Packet& packet, HANDLE hClient);
	virtual ~ReportQueryHandler();

	virtual bool Prehandling();
	virtual bool IsFurtherHandlingNeeded() {return true;}

	static bool CompareMonUnitItems(MonUnitItem * pLeft, MonUnitItem * pRight);
	static ReportAckStruct * MakeReportAckStruct(const ReportTempletHeader * pReportTempletHeader, const std::vector<ReportField *>& ReportFields, const std::vector<CString>& ReportItemStrings, int nTotalStringLength);

protected:
	virtual int Handling();
	virtual ReportTempletAckStruct * GetReportTemplet();
	virtual void ReportGenerated(ReportAckStruct * pReportAckStruct);

	ReportAckStruct * QueryReport(BYTE * pTempletData);
	ReportAckStruct * GenerateReport(ReportTempletHeader * pReportTempletHeader, const std::vector<ReportField *>& ReportFields, const std::vector<MonUnitItem *>& MonUnitItems);
	ReportAckStruct * GenerateReportEx(ReportTempletHeader * pReportTempletHeader, const std::vector<ReportField *>& ReportFields, const std::vector<MonUnitItem *>& MonUnitItems);
	int ConvertReportItemToString(ReportTempletHeader * pReportTempletHeader, const std::vector<ReportItem *>& ReportItems, const std::vector<ReportField *>& ReportFields, std::vector<CString>& ReportItemStrings);
	int ConvertReportItemToString(ReportTempletHeader * pReportTempletHeader, const std::vector<ReportItemEx *>& ReportItems, const std::vector<ReportField *>& ReportFields, std::vector<CString>& ReportItemStrings);
};

#endif // !defined(AFX_REPORTQUERYHANDLER_H__F100DF8B_E06B_49FE_A442_0905A589EE45__INCLUDED_)
